import router from '@/router'
import store from '@/store'
//不用token就能登录的页面
const whitePage = ['/404', '/login']
router.beforeEach(async(to, form, next) => {
    //如果有token
  if (store.state.user.token) {
    if (to.path.toLowerCase() === '/login') {
      next('/')
    } else {
      if (store.state.user.userInfo.id) {
        next()
      }else{
       await store.dispatch("user/getUserInfo")
       next()
      }
    }
  }else{
      if(whitePage.includes(to.path.toLowerCase())){
          next()
      }else{
        //token删除后,重新登录到首页
          next('/login?secede='+to.fullPath)
      }
  }
})
